package com.itheima.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.domain.Category;
import com.itheima.factory.BeanFactory;
import com.itheima.service.CategoryService;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/categoryServlet")
public class CategoryServlet extends BeanServlet {
    CategoryService categoryService = (CategoryService) BeanFactory.getBean("categoryService");


    private void findCategoryAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
       List<Category> categoryList = categoryService.findCategoryAll();
        String value = new ObjectMapper().writeValueAsString(categoryList);
        resp.getWriter().write(value);
    }
}
